<template>
  <!--转增页面-->
  <div class="ziliao zhuanzeng">
    <wv-group title="接收人姓名">
      <wv-input placeholder="请输入姓名" v-model="receiveUserName" :maxlength="11"></wv-input>
    </wv-group>
    <wv-group title="接收人手机号">
      <wv-input placeholder="请输入正确手机号" type="number" v-model="receivePhone" :maxlength="11"></wv-input>
    </wv-group>
    <div class="model" v-show="isShow">
      <div class="bg"></div>
      <div class="modelContent">
        <img src="../../../assets/close.png" alt="" width="15" @click="isShow=false" class="close">
        是否确认转赠？确认后使用短信将发送至接收人手机
        <p class="btn">
          <button class="call" @click="goGive()">确认</button>
          <button class="cancel" @click="isShow=false">取消</button>
        </p>
      </div>
    </div>
    <p class="offer" @click="showGive()">转赠</p>
  </div>
</template>

<script type="text/ecmascript-6">
  import {giveTiyanVipcard} from '../../../../test/unit/http'
  import {Toast} from 'we-vue'

  export default {
    name: 'tiyanzhuanzeng',
    props: {},
    data() {
      return {
        isShow: false,
        activeIndex: 0,
        receivePhone: '',
        receiveUserName: ''
      };
    },
    methods: {
      checkFrom() {
        let msg = {};
        let myUtils = this.$myUtils;
        if (myUtils.isNull(this.receiveUserName)) {
          msg['result'] = false;
          msg['info'] = '请输入接收人姓名';
          return msg;
        }
        if (myUtils.isNull(this.receivePhone)) {
          msg['result'] = false;
          msg['info'] = '请输入接收人手机号';
          return msg;
        }
        if (!myUtils.checkMobile(this.receivePhone)) {
          msg['result'] = false;
          msg['info'] = '请输入正确的接收人手机号';
          return msg;
        }
        msg['result'] = true;
        msg['info'] = '校验成功';
        return msg;
      },
      getActiveIndex() {
        console.log(this.activeIndex)
      },
      showGive() {
        let checkResult = this.checkFrom();
        if (!checkResult.result) {
          Toast.text(checkResult.info);
          return;
        }
        this.isShow = true
      },
      goGive() {
        let accountGoodsId = this.$route.query.accountGoodsId;
        let checkResult = this.checkFrom();
        if (!checkResult.result) {
          Toast.text(checkResult.info);
          return;
        }
        let params = {
          accountGoodsId: accountGoodsId,
          receivePhone: this.receivePhone,
          receiveUserName: this.receiveUserName
        };
        giveTiyanVipcard(params).then(res => {
          console.info(res);
          if (res.code == 100) {
            this.$router.go(-1);
            Toast.text("转赠成功，使用方法短信已发送至接收人手机");
          } else {
            Toast.text("转赠失败")
          }
        })
      }
    },
    created() {
    },
    components: {}
  }
</script>


<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="less" rel="stylesheet/less">
  .ziliao {
    padding: 10px 10px 50px 0;
    text-align: left;
  }

  .way {
    color: #2e94f0;
    padding-left: 15px;
    margin-bottom: 10px;
  }

  .beizhu {
    border-top: 1px solid #eee;
  }

  .des {
    padding-left: 15px;
    color: #111;
    font-size: 20px;
  }

  .descontent {
    color: #666;
    font-size: 15px;
    line-height: 25px;
    padding-left: 15px;
    margin-top: 5px;
    padding-bottom: 60px;
  }

  .bg {
    background-color: rgba(0, 0, 0, 0.3);
    width: 100%;
    height: 100%;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 50px;
  }

  .model .modelContent {
    background-color: #fff;
    border-radius: 8px;
    position: fixed;
    left: 50%;
    top: 50%;
    margin-left: -43%;
    margin-top: -111px;
    z-index: 2;
    padding: 30px 10px 20px;
    width: 80%;
    font-size: 16px;
    color: #111;

    .close {
      position: absolute;
      right: 10px;
      top: 10px
    }

    div {
      text-align: left;
      width: 75%;
      margin: 20px auto;
    }

    .list {
      font-size: 15px;
      margin-bottom: 20px;

      li:first-child {
        color: #56a7ed;
        margin-bottom: 5px;

        img {
          vertical-align: middle;
          margin-right: 5px;
        }
      }
    }

    .btn {
      button {
        height: 42px;
        line-height: 42px;
        color: #fff;
        outline: none;
        border: none;
        width: calc(50% - 20px);
        border-radius: 8px;
      }

      :first-child {
        background-color: #ccc;
        margin-right: 20px;
      }

      :last-child {
        background-color: #fc8c50;
      }

      .call {
        background-color: #2e94f0;
      }

      .cancel {
        background-color: #ccc;
      }
    }
  }

  .offer {
    position: fixed;
    bottom: 0;
    width: 100%;
    text-align: center;
    background-image: linear-gradient(to left, #4c92ed, #61beec);
    height: 50px;
    line-height: 50px;
    color: #fff;
  }
</style>
